﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YJKExcelFormTool.DataDefine;

namespace YJKExcelFormTool.Forms
{
	public partial class CombinationOfAttributesForm : System.Windows.Forms.Form
	{
		public CombinationOfAttributesForm(CombinationOfAttributes allAttributesOfCategory, CombinationOfAttributes currentCombination)
		{
			this.m_AllAttributesOfCategory = allAttributesOfCategory;
			this.m_CurrentCombination = currentCombination;
			this.InitializeComponent();
			this.InitializeData();
		}

		private void InitializeData()
		{
			if (this.m_CurrentCombination == null)
			{
				foreach (string value in this.m_AllAttributesOfCategory.AttributesName)
				{
					DataGridViewRow dataGridViewRow = new DataGridViewRow();
					DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
					dataGridViewTextBoxCell.Value = value;
					dataGridViewRow.Cells.Add(dataGridViewTextBoxCell);
					this.dgvAttributeList.Rows.Add(dataGridViewRow);
				}
				return;
			}
			for (int i = 0; i < this.m_AllAttributesOfCategory.AttributesName.Count; i++)
			{
				string attributeName = this.m_AllAttributesOfCategory.AttributesName[i];
				int num = this.m_CurrentCombination.AttributesName.FindIndex((string s) => s.CompareTo(attributeName) == 0);
				if (num == -1)
				{
					DataGridViewRow dataGridViewRow2 = new DataGridViewRow();
					DataGridViewTextBoxCell dataGridViewTextBoxCell2 = new DataGridViewTextBoxCell();
					dataGridViewTextBoxCell2.Value = attributeName;
					dataGridViewRow2.Cells.Add(dataGridViewTextBoxCell2);
					this.dgvAttributeList.Rows.Add(dataGridViewRow2);
				}
				else
				{
					DataGridViewRow dataGridViewRow3 = new DataGridViewRow();
					DataGridViewTextBoxCell dataGridViewTextBoxCell3 = new DataGridViewTextBoxCell();
					dataGridViewTextBoxCell3.Value = attributeName;
					dataGridViewRow3.Cells.Add(dataGridViewTextBoxCell3);
					DataGridViewTextBoxCell dataGridViewTextBoxCell4 = new DataGridViewTextBoxCell();
					string text = this.m_CurrentCombination.Delimiter[num];
					if (text.CompareTo("") == 0)
					{
						text = "_";
					}
					dataGridViewTextBoxCell4.Value = text;
					dataGridViewRow3.Cells.Add(dataGridViewTextBoxCell4);
					this.dbgSelectAttributeList.Rows.Add(dataGridViewRow3);
				}
			}
		}

		private void CombinationOfAttributesForm_FormClosing(object sender, FormClosingEventArgs e)
		{
		}

		public void GetCombinationOfAttributes(ref List<string> attributeList, ref List<string> delimiterList)
		{
			for (int i = 0; i < this.dbgSelectAttributeList.RowCount; i++)
			{
				DataGridViewCellCollection cells = this.dbgSelectAttributeList.Rows[i].Cells;
				attributeList.Add(cells[0].Value.ToString());
				string text = cells[1].Value.ToString();
				if (text.CompareTo("") == 0)
				{
					text = "_";
				}
				delimiterList.Add(text);
			}
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			DataGridViewRow currentRow = this.dgvAttributeList.CurrentRow;
			if (currentRow != null)
			{
				string value = currentRow.Cells[0].Value.ToString();
				this.dgvAttributeList.Rows.Remove(currentRow);
				DataGridViewRow dataGridViewRow = new DataGridViewRow();
				DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
				dataGridViewTextBoxCell.Value = value;
				dataGridViewRow.Cells.Add(dataGridViewTextBoxCell);
				DataGridViewTextBoxCell dataGridViewTextBoxCell2 = new DataGridViewTextBoxCell();
				dataGridViewTextBoxCell2.Value = "_";
				dataGridViewRow.Cells.Add(dataGridViewTextBoxCell2);
				this.dbgSelectAttributeList.Rows.Add(dataGridViewRow);
			}
		}

		private void btnRemove_Click(object sender, EventArgs e)
		{
			DataGridViewRow currentRow = this.dbgSelectAttributeList.CurrentRow;
			if (currentRow != null)
			{
				string value = currentRow.Cells[0].Value.ToString();
				this.dbgSelectAttributeList.Rows.Remove(currentRow);
				DataGridViewRow dataGridViewRow = new DataGridViewRow();
				DataGridViewTextBoxCell dataGridViewTextBoxCell = new DataGridViewTextBoxCell();
				dataGridViewTextBoxCell.Value = value;
				dataGridViewRow.Cells.Add(dataGridViewTextBoxCell);
				this.dgvAttributeList.Rows.Add(dataGridViewRow);
			}
		}

		private CombinationOfAttributes m_AllAttributesOfCategory;

		private CombinationOfAttributes m_CurrentCombination;
	}
}
